<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('类型')">
            <el-select v-model="form.type" value="" :placeholder="$t('类型')">
              <el-option
                v-for="dict in typeDict"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('幅度(%)')" prop="numbers">
            <Ratio v-model="form.numbers" :precision="2" :step="0.1" :controls="false" :placeholder="$t('幅度')" />
          </el-form-item>
        </el-col>
        <!--<el-col :span="12">
          <span style=" font-weight: 700; font-size: 14px; color: #606266; line-height: 36px;">{{ $t('触发状态') }} :</span>
          <span :v-if="form.status !== 'YFS' && form.status !== 'FSYC'">未触发</span>
          <span :v-if="form.status === 'YFS' && form.status !== undefined && form.status !== '' || form.status !== null" style="color: green;">已发送</span>
          <span :v-if="form.status === 'FSYC' && form.status !== undefined && form.status !== '' || form.status !== null" style="color: red;">发生异常</span>
        </el-col>-->
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="listed:closeMonitor" />
    </div>
  </div>
</template>
<script>
import {
  saveListedClosedMonitor,
  getDCPMonitoring
} from '@/api/deal/listed/monitor/listedCloseMonitor'

export default {
  props: {
    listedId: {
      type: String,
      required: false,
      default: ''
    },
    dealId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 遮罩层
      loading: false,
      // 类型字典
      typeDict: [],
      // 表单校验
      rules: {
        numbers: [{ required: true, message: this.$t('必填信息'), trigger: 'change' }],
        type: [{ required: true, message: this.$t('必填信息'), trigger: 'change' }]
      }
    }
  },
  async created() {
    const response = await this.getDicts('stockMonitoringType')
    this.typeDict = response.data
  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getDCPMonitoring(data.id).then(response => {
          this.form = response.data
        })
      } else {
        this.reset()
      }
      console.log(this.form)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.dealId,
        listedId: this.listedId,
        type: undefined,
        numbers: undefined,
        status: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.formOpen = false
      // 刷新list页面
      this.$parent.$parent.getList()
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveListedClosedMonitor(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    }

  }

}
</script>
